class Star
  
  attr_reader :star_body, :star_shape, :x, :y
  
  def initialize(window)
    # give it the chipmunk params
    @star_body = CP::Body.new(0.0001, 0.0001)
    @star_shape = CP::Shape::Circle.new(@star_body, 25/2, CP::Vec2.new(0.0, 0.0))
    @star_anim = Gosu::Image::load_tiles(window, "media/Star.png", 25, 25, false)
    @star_shape.collision_type = :star
    @star_shape.body.p = CP::Vec2.new(rand * SCREEN_WIDTH, 10) # position
    @star_shape.body.v = CP::Vec2.new(0.0, 275.0) # velocity
    @star_shape.body.a = (3*Math::PI/2.0) # angle in radians - faces towards top of screen
    
    @x = @star_shape.body.p.to_a[0]
    @y = @star_shape.body.p.to_a[1]
    
    # random color definition
    @color = Gosu::Color.new(0xff000000)
    @color.red = rand(255 - 40) + 40
    @color.green = rand(255 - 40) + 40
    @color.blue = rand(255 - 40) + 40
    
    # put it on the playfield
    $space.add_body(@star_body)
    $space.add_shape(@star_shape)
  end
  
  def draw  
    img = @star_anim[Gosu::milliseconds / 100 % @star_anim.size];
    img.draw(@star_shape.body.p.to_a[0] - img.width / 2.0,
             @star_shape.body.p.to_a[1] - img.height / 2.0,
             ZOrder::Stars, 3, 3, @color, :additive)
  end

end